//
//  ZJFSecondCollectionViewCell.m
//  OurTourism
//
//  Created by 张金峰 on 15/11/27.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "ZJFSecondCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
@interface ZJFSecondCollectionViewCell ()
@property (nonatomic, retain)UIImageView *backImg;
@property (nonatomic, retain)UILabel *labelTilte;
@property (nonatomic, retain)UIImageView *dieViewCountImg;
@property (nonatomic, retain)UILabel *viewCountLabel;
@property (nonatomic, retain)UIImageView *dieLikeImg;
@property (nonatomic, retain)UILabel *likeLable;
@property (nonatomic, retain)UILabel *whiteLable;
@property (nonatomic, strong)UIImageView *heihei;
@end
@implementation ZJFSecondCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView
{
    self.backImg = [[UIImageView alloc]init];
    [self.contentView addSubview:self.backImg];
    self.backImg.backgroundColor = [UIColor redColor];
    self.backImg.contentMode = UIViewContentModeScaleAspectFill;
    self.backImg.clipsToBounds = YES;
    
    
    self.labelTilte = [[UILabel alloc]init];
   // self.labelTilte.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.labelTilte];
    self.labelTilte.font = [UIFont systemFontOfSize:15];
    self.labelTilte.numberOfLines = 2;
    
    self.dieViewCountImg = [[UIImageView alloc]init];
    self.dieViewCountImg.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.dieViewCountImg];
    self.dieViewCountImg.image = [UIImage imageNamed:@"chakan"];
    
    self.viewCountLabel = [[UILabel alloc]init];
  //  self.viewCountLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.viewCountLabel];
    self.viewCountLabel.font = [UIFont systemFontOfSize:10];
    
    self.dieLikeImg = [[UIImageView alloc]init];
    self.dieLikeImg.backgroundColor = [UIColor blueColor];
    self.dieLikeImg.image = [UIImage imageNamed:@"like"];
    [self.contentView addSubview:self.dieLikeImg];
    
    self.likeLable = [[UILabel alloc]init];
  //  self.likeLable.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.likeLable];
    self.likeLable.font = [UIFont systemFontOfSize:10];
    
    self.heihei = [[UIImageView alloc] init];
    [self.backImg addSubview:self.heihei];
    
    self.whiteLable = [[UILabel alloc] init];
    self.whiteLable.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    [self.contentView addSubview:self.whiteLable];
    
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
    [super applyLayoutAttributes:layoutAttributes];
    [self.backImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(0);
        make.left.mas_equalTo(self.contentView.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.frame.size.width, layoutAttributes.frame.size.height * 0.7));
    }];
    
    
    [self.heihei mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backImg.mas_top).offset(0);
        make.left.mas_equalTo(self.backImg.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.frame.size.width, layoutAttributes.frame.size.height * 0.7));
    }];

    [self.labelTilte mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backImg.mas_bottom).offset(5);
        make.left.mas_equalTo(self.backImg.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.frame.size.width - 20, 45));
    }];

    [self.viewCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.dieViewCountImg.mas_top);
        make.left.mas_equalTo(self.dieViewCountImg.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(60, 15));
    }];

    [self.dieViewCountImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labelTilte.mas_bottom).offset(5);
        make.left.mas_equalTo(self.labelTilte.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.dieLikeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.viewCountLabel.mas_top);
        make.left.mas_equalTo(self.viewCountLabel.mas_right).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.likeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.dieLikeImg.mas_top);
        make.left.mas_equalTo(self.dieLikeImg.mas_right).offset(0);
        make.size.mas_equalTo(CGSizeMake(60, 15));
    }];
    
    [self.whiteLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backImg.mas_bottom).offset(82);
        make.left.mas_equalTo(self.backImg.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.frame.size.width, 10));
    }];
  
}

- (void)setGuideModel:(ZJFguiDeModel *)guideModel
{
    if (_guideModel != guideModel) {
        _guideModel = guideModel;
    }
    self.labelTilte.text = guideModel.title;
    if (guideModel.viewCnt.integerValue / 1000 < 0) {
        self.viewCountLabel.text = guideModel.viewCnt;
    }
    else
    {
        NSInteger i = guideModel.viewCnt.integerValue / 1000;
        NSInteger j = guideModel.viewCnt.integerValue % 1000 / 100;
        self.viewCountLabel.text = [NSString stringWithFormat:@"%ld%@%ld%@",i, @".", j, @"k"];
    }
    
    self.likeLable.text = guideModel.cntFav;
    
    NSString *url = [NSString stringWithFormat:@"%@%@%@", guideModel.picdomain,@"upload/",guideModel.coverpic];
   [self.backImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"load"]];
    
    self.heihei.image = [UIImage imageNamed:@"2222"];
    
}




@end
